package cn.doctor.assistant.pad.ui.huifang;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.doctor.assistant.pad.R;
import cn.doctor.assistant.pad.entity.Recall;

/**
 * Created by jiaolf on 2016/4/15.
 */
public class RecallAdapter extends BaseAdapter {

    private List<Recall> items;
    private Context context;

    public RecallAdapter(Context context, List<Recall> data) {
        this.context = context;
        items = data;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_recall_info, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        Recall recall = items.get(position);
        holder.listItemId.setText((position+1)+"");
        holder.listItemName.setText(recall.getName());
        holder.listItemKeshi.setText(recall.getDeptName());
        holder.listItemMainDoctor.setText(recall.getDoctor());
        holder.listItemDiagnose.setText(recall.getNote());
        holder.listItemZhuyuanNumber.setText(recall.getInhiscode());
        holder.listItemStartDate.setText(recall.getInDate());
        holder.listItemEndDate.setText(recall.getOutDate());
        holder.listItemRecallCount.setText(recall.getFollowedTimes()+"");

        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.list_item_id)
        TextView listItemId;
        @InjectView(R.id.list_item_name)
        TextView listItemName;
        @InjectView(R.id.list_item_keshi)
        TextView listItemKeshi;
        @InjectView(R.id.list_item_main_doctor)
        TextView listItemMainDoctor;
        @InjectView(R.id.list_item_diagnose)
        TextView listItemDiagnose;
        @InjectView(R.id.list_item_zhuyuan_number)
        TextView listItemZhuyuanNumber;
        @InjectView(R.id.list_item_start_date)
        TextView listItemStartDate;
        @InjectView(R.id.list_item_end_date)
        TextView listItemEndDate;
        @InjectView(R.id.list_item_recall_count)
        TextView listItemRecallCount;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
